export default {
  name: "contract-approval-manage",
  data() {
    return {
      isActive: 0,
      isShow: true,
      tableTopBtn: [
        { label: "全部", value: "approvalAll" },
        { label: "待审批", value: "approvalPending" },
        { label: "已审批", value: "approvalPass" },
      ],
      // 非锁定表格
      // 非锁定表格
      unfixedTableThead: [{
        label: "审批类型",
        prop: "todoData.businessBillTypeName",
        width: "100"
      },
      {
        label: "代付单名称",
        prop: "businessData.replacePayName",
        width: "200",
        checked: true,
        align: "left"
      },
      {
        label: "合同名称",
        prop: "businessData.contractName",
        width: "200",
        checked: true,
        align: "left"
      },
      {
        label: "需方名称",
        prop: "businessData.needName",
        width: "200",
        checked: true,
        align: "left"
      },
      {
        label: "付款金额(元)",
        prop: "businessData.paymentMoney",
        width: "100",
        checked: true,
        align: "right",
        headerAlign: "left"
      },
      {
        label: "供方名称",
        prop: "businessData.supplierName",
        width: "200",
        checked: true,
        align: "left"
      },
      {
        label: "填报单位",
        prop: "businessData.reportName",
        width: "200",
        checked: true,
        align: "left"
      },
      {
        label: "联系人",
        prop: "businessData.contacts",
        width: "90",
        checked: true,
        align: "left"
      },
      {
        label: "编制日期",
        prop: "businessData.reportTime",
        width: "100",
        checked: true,
        align: "left"
      },
      {
        label: "审批状态",
        prop: "todoData.workItemStatusString",
        width: "100",
        checked: true,
        align: "left"
      }
      ],
      // 审批类型
      // storageTypeList: [
      //   { label: "待审批", value: "1" },
      //   { label: "已审批", value: "2" }
      // ],
      // 审批状态
      workItemStatusList: [
        { label: "待审批", value: "0" },
        { label: "已审批", value: "1" },
      ],
      // 审批类型
      approvalTypeList: [
        { label: "财务出库", value: "S0407" },
        { label: "财务出库冲销", value: "S0408" },
      ],
    };
  },
  methods: {
    // 默认渲染表格
    renderTable() {
      const localTableData = localStorage.getItem(this.tableName) ?
        JSON.parse(localStorage.getItem(this.tableName)) : [];
      let unfixedTableThead = this.unfixedTableThead.concat(
        this.fixedTableThead
      );
      let localTableDataStr = localTableData.map(
        ({ label, prop, formatter, align }) =>
          JSON.stringify({ label, prop, formatter, align })
      );
      let unfixedTableTheadStr = unfixedTableThead.map(
        ({ label, prop, width, formatter, align }) =>
          JSON.stringify({ label, prop, formatter, align })
      );

      if (localTableData.length === unfixedTableThead.length) {
        let flag = localTableDataStr.every((item) =>
          unfixedTableTheadStr.includes(item)
        );
        if (flag) {
          // 完全相同
          this.tableTheadOptions = localTableData;
          this.tableThead = localTableData;
          this.unfixedTableThead = localTableData.filter((item) => {
            return !this.fixedTableThead.find(
              (cItem) => item.prop === cItem.prop
            );
          });
        } else {
          // 长度相同但值不同
          this.tableThead = this.unfixedTableThead.concat(this.fixedTableThead);
          const comment = JSON.stringify(this.tableThead);
          localStorage.setItem(this.tableName, comment);
          const localTableData = JSON.parse(
            localStorage.getItem(this.tableName)
          );
          this.tableTheadOptions = localTableData;
        }
      } else {
        // 长度不同
        this.tableThead = this.unfixedTableThead.concat(this.fixedTableThead);
        const comment = JSON.stringify(this.tableThead);
        localStorage.setItem(this.tableName, comment);
        const localTableData = JSON.parse(localStorage.getItem(this.tableName));
        this.tableTheadOptions = localTableData;
      }
    },

    // 页签跳转
    tableTopChange({ value }) {
      this.isFocus = value;
      this.$router.push(`/paymentManagement/paidApprove/${value}`);
    },

    // 跳转详情页
    handleGoDetail(row, index, from) {
      const { todoData, businessData } = row;
      const { businessBillTypeCode } = todoData;
      const { id } = businessData;
      const jumpInformation = {
        S0604: { states: "paidDetail" },
      };

      this.$router.push({
        path: `/paymentManagement/paidApprove/approvalDetail/`,
        query: {
          id,
          ...jumpInformation[businessBillTypeCode],
          // name: billName,
          from,
          states: "paidDetail"
        },
      });
    },

    // 跳转审核页
    handleGoApproval(row) {
      const { todoData, businessData } = row;
      const { businessBillTypeCode } = todoData;
      const { id } = businessData;

      this.$store.dispatch("setBusinessList", todoData);
      const businessList = JSON.stringify(todoData);
      sessionStorage.setItem("businessList", businessList);

      const jumpInformation = {
        S0604: { states: "paidApproval" },
      };
      this.$router.push({
        path: `/paymentManagement/paidApprove/approvalDetail/`,
        query: {
          id,
          ...jumpInformation[businessBillTypeCode],
          from: "pending",
        },
      });
    },
    //跳合同
    handleGoContract(row) {
      if (row.businessData.contractType == 1) {
        this.$router.push({
          path: "/contractManagement/contractAgreement/item-detail",
          query: {
            concId: row.businessData.contractId,
            ifApprovingStatus: 0,
            parameterList: 1
          }
        });
      } else {
        this.$router.push({
          path: "/contractManagement/contractAgreement/item-detail",
          query: {
            concId: row.businessData.contractId,
            ifApprovingStatus: 0,
            parameterList: 1
          }
        });
      }
    }
  },
};
